package com.yswy.common.zfbOrder;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.*;
import com.alipay.api.domain.*;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.yswy.common.enums.AlipayMethodEnums;
import com.yswy.common.enums.DateUnitEnums;
import com.yswy.common.enums.PayMethodEnums;
import com.yswy.common.utils.DateUtils;
import com.yswy.common.utils.OrderNoCenter;
import com.yswy.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Slf4j
public class ZfbOrderUtil {
    //正式
    private static String serverUrl = "https://openapi.alipay.com/gateway.do";
    //沙箱
//    private static String serverUrl = "https://openapi.alipaydev.com/gateway.do";
    private static String format = "json";
    private static String charset = "UTF-8";
    private static String signType = "RSA2";
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 初始化支付宝
     * @param zfbKeyVo
     * @return
     * @throws AlipayApiException
     */
    public static AlipayClient getAlipayClient(ZfbKeyVo zfbKeyVo) {
        try {
            AlipayClient alipayClient = null ;
            if (zfbKeyVo.getSingType() == 0){
                String privatekey = zfbKeyVo.getJavaKey();
                String publickey= zfbKeyVo.getZfbKey();
                alipayClient = new DefaultAlipayClient(serverUrl, zfbKeyVo.getAppId(), privatekey,
                        format, charset, publickey, signType);
            }else if (zfbKeyVo.getSingType() == 0){
                String prkey = zfbKeyVo.getJavaKey();
                //支付宝公钥证书文件路径
                String certPath = zfbKeyVo.getCertPath();
                //应用公钥证书路径
                String publicCertPath = zfbKeyVo.getPublicCertPath();
                //支付宝CA根证书文件路径
                String rootCertPath= zfbKeyVo.getRootCertPath();
                CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
                certAlipayRequest.setServerUrl(serverUrl);  //gateway:支付宝网关（固定）https://openapi.alipay.com/gateway.do
                certAlipayRequest.setAppId(zfbKeyVo.getAppId());  //APPID 即创建应用后生成,详情见创建应用并获取 APPID
                certAlipayRequest.setPrivateKey(prkey);  //开发者应用私钥，由开发者自己生成
                certAlipayRequest.setFormat(format);  //参数返回格式，只支持 json 格式
                certAlipayRequest.setCharset(charset);  //请求和签名使用的字符编码格式，支持 GBK和 UTF-8
                certAlipayRequest.setSignType(signType);  //商户生成签名字符串所使用的签名算法类型，目前支持 RSA2 和 RSA，推荐商家使用 RSA2。
                certAlipayRequest.setCertPath(certPath); //应用公钥证书路径（app_cert_path 文件绝对路径）
                certAlipayRequest.setAlipayPublicCertPath(publicCertPath); //支付宝公钥证书文件路径（alipay_cert_path 文件绝对路径）
                certAlipayRequest.setRootCertPath(rootCertPath);  //支付宝CA根证书文件路径（alipay_root_cert_path 文件绝对路径）
                alipayClient = new DefaultAlipayClient(certAlipayRequest);
            }
            return alipayClient ;
        }catch (Exception e){
            e.printStackTrace();
            throw new IllegalArgumentException("初始化支付宝失败");
        }

    }

    /**
     * 获取支付字符串
     * @param zfbKeyVo 支付宝支付参数
     * @param orderid 订单id
     * @param amount 订单价格
     * @param subject 商品信息
     * @param returnUrl 支付成功后返回页面
     * @param callbackUrl 回调接口
     * @param methodType 支付类型
     * @return
     * @throws AlipayApiException
     */
    public static String getPayMessage(ZfbKeyVo zfbKeyVo
            ,String orderid
            ,int amount
            ,String subject
            ,String returnUrl
            ,String callbackUrl
            ,int methodType,
            String externalAgreementNo,
            String signNotifyUrl ,
            PeriodRuleParams periodRuleParams ){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        switch (methodType) {
            case AlipayMethodEnums.QUICK_MSECURITY_PAY:
                AlipayTradeAppPayRequest appRequest = new AlipayTradeAppPayRequest();


                AlipayTradeAppPayModel app_model = new AlipayTradeAppPayModel();
                app_model.setTimeExpire(simpleDateFormat.format(DateUtils.addDateNum(new Date(), DateUnitEnums.HOUR.getMessage(), 10))); // 订单绝对超时时间。
                app_model.setOutTradeNo(String.valueOf(orderid));
                app_model.setTotalAmount(String.valueOf((float) amount / 100));// 订单总金额，单位为元，精确到小数点后两位
                app_model.setSubject(subject);// 必填，商品的标题/交易标题/订单标题/订单关键字等。- 奇玩盒子商品
                app_model.setProductCode(AlipayMethodEnums.kv.getOrDefault(methodType, AlipayMethodEnums.APP.getMessage()));
                app_model.setPassbackParams(String.valueOf(orderid));// 回传参数:商户网站唯一订单号。

                appRequest.setNotifyUrl(callbackUrl);
                appRequest.setBizModel(app_model);

                AlipayTradeAppPayResponse appResponse = null;
                try {
                    appResponse = alipayClient.sdkExecute(appRequest);
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                }
                return appResponse.getBody();
            case AlipayMethodEnums.QUICK_WAP_WAY:
                AlipayTradeWapPayRequest wapRequest = new AlipayTradeWapPayRequest();

                AlipayTradeWapPayModel wap_model = new AlipayTradeWapPayModel();
                wap_model.setOutTradeNo(String.valueOf(orderid));
                wap_model.setTotalAmount(String.valueOf((float) amount / 100));// 订单总金额，单位为元，精确到小数点后两位
                wap_model.setSubject(subject);// 必填，商品的标题/交易标题/订单标题/订单关键字等。- 奇玩盒子商品
                wap_model.setProductCode(AlipayMethodEnums.kv.getOrDefault(methodType, AlipayMethodEnums.WAP.getMessage()));
                wap_model.setPassbackParams(String.valueOf(orderid));// 回传参数:商户网站唯一订单号。
                wap_model.setTimeExpire(simpleDateFormat.format(DateUtils.addDateNum(new Date(),DateUnitEnums.HOUR.getMessage(),10))); // 订单绝对超时时间。

                wapRequest.setBizModel(wap_model);
                wapRequest.setNotifyUrl(callbackUrl);

                wapRequest.setReturnUrl(returnUrl);

                AlipayTradeWapPayResponse wapResponse = null;
                try {
                    wapResponse = alipayClient.sdkExecute(wapRequest);
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                }
                return wapResponse.getBody();
            case AlipayMethodEnums.CYCLE_PAY_AUTH:
                AlipayTradeAppPayRequest cycleRequest = new AlipayTradeAppPayRequest();
                AlipayTradeAppPayModel cycle_model = new AlipayTradeAppPayModel();

                cycle_model.setTimeExpire(simpleDateFormat.format(DateUtils.addDateNum(new Date(),DateUnitEnums.HOUR.getMessage(),10))); // 订单绝对超时时间。
                cycle_model.setOutTradeNo(String.valueOf(orderid));
                cycle_model.setTotalAmount(String.valueOf((float) amount / 100));// 订单总金额，单位为元，精确到小数点后两位
                cycle_model.setSubject(subject);// 必填，商品的标题/交易标题/订单标题/订单关键字等。- 奇玩盒子商品
                cycle_model.setProductCode(zfbKeyVo.getProductCode());
//                cycle_model.setProductCode("QUICK_MSECURITY_PAY");

                cycle_model.setPassbackParams(String.valueOf(orderid));// 回传参数:商户网站唯一订单号。

                SignParams signParams = new SignParams();
                signParams.setSignScene("INDUSTRY|DEFAULT_SCENE");
//                signParams.setSignScene("INDUSTRY|PSMH");

                signParams.setPersonalProductCode("CYCLE_PAY_AUTH_P");

                signParams.setExternalAgreementNo(externalAgreementNo);
                signParams.setSignNotifyUrl(signNotifyUrl);
                AccessParams accessParams = new AccessParams();
                accessParams.setChannel("ALIPAYAPP");
                signParams.setAccessParams(accessParams);
                signParams.setPeriodRuleParams(periodRuleParams);

                cycle_model.setAgreementSignParams(signParams);


                cycleRequest.setNotifyUrl(callbackUrl);
                cycleRequest.setBizModel(cycle_model);

                AlipayTradeAppPayResponse cycleResponse = null;
                try {
                    cycleResponse = alipayClient.sdkExecute(cycleRequest);
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                }
                return cycleResponse.getBody();
            case AlipayMethodEnums.GENERAL_WITHHOLDING:
                AlipayTradeAppPayRequest cycleRequestGENERAL = new AlipayTradeAppPayRequest();
                //签约接入的方式
                JSONObject accessParamsJson = new JSONObject();
                accessParamsJson.put("channel","ALIPAYAPP");
                JSONObject periodRuleParamsJson = new JSONObject();
                periodRuleParamsJson.put("period_type",periodRuleParams.getPeriodType());
                periodRuleParamsJson.put("period",periodRuleParams.getPeriod());
                periodRuleParamsJson.put("execute_time",periodRuleParams.getExecuteTime());
                periodRuleParamsJson.put("single_amount",periodRuleParams.getSingleAmount());
                periodRuleParamsJson.put("total_amount",periodRuleParams.getTotalAmount());
                periodRuleParamsJson.put("total_payments",periodRuleParams.getTotalPayments());


                JSONObject signParamsJson = new JSONObject();
                signParamsJson.put("sign_scene","INDUSTRY|DEFAULT_SCENE");
                signParamsJson.put("personal_product_code","CYCLE_PAY_AUTH_P");
                signParamsJson.put("product_code",zfbKeyVo.getProductCode());
                signParamsJson.put("sign_notify_url",signNotifyUrl);
                signParamsJson.put("access_params",accessParamsJson);
                signParamsJson.put("period_rule_params",periodRuleParamsJson);
                signParamsJson.put("external_agreement_no" ,externalAgreementNo );


                JSONObject bizContent = new JSONObject();
                // 订单绝对超时时间。
                bizContent.put("time_expire" , simpleDateFormat.format(DateUtils.addDateNum(new Date(),DateUnitEnums.HOUR.getMessage(),10)));
                bizContent.put("out_trade_no" ,String.valueOf(orderid) );
                // 订单总金额，单位为元，精确到小数点后两位
                bizContent.put("total_amount" , String.valueOf((float) amount / 100));
                // 必填，商品的标题/交易标题/订单标题/订单关键字等。
                bizContent.put("subject" , subject);
                bizContent.put("product_code" , zfbKeyVo.getProductCode());
                //回传参数:商户网站唯一订单号。
                bizContent.put("passback_params" ,String.valueOf(orderid) );

                bizContent.put("agreement_sign_params" ,signParamsJson );


                cycleRequestGENERAL.setNotifyUrl(callbackUrl);
                cycleRequestGENERAL.setBizContent(bizContent.toString());

                AlipayTradeAppPayResponse cycleResponseGENERAL = null;
                try {
                    cycleResponseGENERAL = alipayClient.sdkExecute(cycleRequestGENERAL);
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                }
                return cycleResponseGENERAL.getBody();
            default:
                throw new IllegalArgumentException("无效的支付方式");
        }
    }

    /**
     * 统一收单交易支付接口
     * @param zfbKeyVo 支付宝支付参数
     * @param subject 支付宝唯一用户号
     * @param agreement_no 用户的支付宝登录账号
     * @param callbackUrl
     *
     * @throws AlipayApiException
     */
    public static AlipayTradePayResponse AlipayTradePayRequest(ZfbKeyVo zfbKeyVo ,String orderid
            ,int amount
            ,String subject
            ,String agreement_no
            ,String callbackUrl){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayTradePayRequest request = new AlipayTradePayRequest();
        //异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl(callbackUrl);
        /******必传参数******/
        JSONObject bizContent = new JSONObject();
        //商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", orderid);
        //支付金额，最小值0.01元
        bizContent.put("total_amount", String.valueOf((float) amount / 100));
        //订单标题，不可使用特殊符号
        bizContent.put("subject", subject);
        //周期扣款场景固定传值CYCLE_PAY_AUTH
        bizContent.put("product_code", zfbKeyVo.getProductCode());

        JSONObject pay_params = new JSONObject();
        pay_params.put("async_type","NORMAL_ASYNC");
        bizContent.put("pay_params", pay_params);

        //协议信息
        JSONObject agreementParams = new JSONObject();

        agreementParams.put("agreement_no", agreement_no);//周期扣款签约协议后返回的agreement_no
        bizContent.put("agreement_params", agreementParams);

        request.setBizContent(bizContent.toString());
        AlipayTradePayResponse   response = new AlipayTradePayResponse();
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            log.info("周期付款订单调用失败" + e.getMessage());
            response.setSubMsg(e.getMessage());
            response.setSubCode(e.getErrCode());
            e.printStackTrace();
        }

        return response ;
//        if(response.isSuccess()){
//            log.info("调用成功");
//            return true ;
//        } else {
//            log.info("周期付款订单调用失败  "+response.getSubMsg() + "订单ID ");
//            return false ;
//        }
    }

    /**
     * 统一收单交易关闭
     * @param zfbKeyVo 支付宝支付参数
     *
     * @throws AlipayApiException
     */
    public static Boolean AlipayTradeCloseRequest(ZfbKeyVo zfbKeyVo ,String trade_no){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no",trade_no);
        request.setBizContent(bizContent.toString());
        AlipayTradeCloseResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){

            System.out.println("关闭订单调用成功");
            return true ;
        } else {

            System.out.println("关闭订单调用失败" + response.getSubMsg());
            return false ;
        }
    }






//    public TransferRequestDto transferRequest(ZfbKeyVo zfbKeyVo,String orderId , String phone, String name , Integer money , String msg) {
//        TransferRequestDto transferRequestDto = new TransferRequestDto() ;
//        try {
//            AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
//            transferRequestDto.setOrderId(orderId);
//            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//            Double trans_amount = money.doubleValue()/100.0 ;
//            request.setBizContent("{" +
//                    "\"out_biz_no\":\""+orderId+"\"," +
//                    "\"trans_amount\":"+trans_amount+"," +
//                    "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
//                    "\"biz_scene\":\"DIRECT_TRANSFER\"," +
//                    "\"order_title\":\"转账\"," +
//                    "\"payee_info\":{" +
//                    "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
//                    "\"identity\":\""+phone+"\"," +
//                    "\"name\":\""+name+"\"," +
//                    "}," +
//                    "\"remark\":\""+msg+"\"," +
//                    "\"business_params\":\"{\\\"payer_show_name_use_alias\\\":\\\"true\\\"}\"" +
//                    "}");
//            AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
//            transferRequestDto.setMsg(response.getSubMsg());
//            if (response.isSuccess()) {
//                log.info("支付宝转账成功" + response.getSubMsg());
//                transferRequestDto.setIstrue(true);
//            } else {
//                log.info("支付宝转账失败"+response.getSubMsg());
//                transferRequestDto.setIstrue(false);
//            }
//            return transferRequestDto ;
//        }catch (Exception e){
//            e.printStackTrace();
//            transferRequestDto.setIstrue(false);
//            transferRequestDto.setMsg("转账失败");
//            return transferRequestDto ;
//
//        }
//    }




    public static void main(String[] args) {


        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipay.com/gateway.do"
                ,"2021004116687081",
                "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC1O0DrfeVmRWNVOMokHqG+GacK2h0NdVrBZNl8J64QBK61r4wX/WU9VzXO3YlfO4FiuMnpgmqbBWtPwFchsE5A0BvsQXC7M/yv6Vqp5MFe+pt3D6kpxs8HU339BOY2+NRoBGcvJzQVU5qUEux20iAWfvG6msVepnXtLkutBBJiECQiaM4TJLEtaYDiTJauje+leAmILFagSaLWsbLzI0Jtq2Anc0i8yQ3to+KtFuV7G1nK8AFXsC+TV3bnnee8DewJ2Xo1/TOQMRvkIjEB3nCiwopdHKu67D/CbAL5tdN4RfkvpiUiT8Aa2/Xbd7DQDOvNcmV9a664Jm0cv4qE0tqxAgMBAAECggEBAIRL0fNWfvxuULnob994IPglv8PzPtwRPAQLO5wfVzhIQsVMdccZaisiG5x8KgjD5oqLfJGia3HovdKFBNYJ3sX/ZTLM/p8Zry82+MEmxWYxKQX7/7AIeh7N+x2V0vx0HpIkDLLmOmYLFr9bJRUEBPqHBq0CyGt0todCkWmmnEjKYxTxDia+LcAWVH23QnWsaHZ8rky7R9Vv9bDU8qB1yRfbA32L9+VG1JzFB+pze2RMe9YGu/Wq/DVp708f7eXxeWfeFIzuVDL4qeuT32hqTlp5k2edwZXDXILf38AQMn21CoB7MhJ+bsaLqLfvtydWySiuBTfRREiCae8Zyb5oXAECgYEA/Q+R8eDPUJUYt5kzrtYEJ5EPkIc3f5E7RmdWbCwu+9+y01yMZaldLUCVd19SMoYZb0LFWBpItI2k5ibIyp3vR6+4wZNi5/MIofX+0XqRuJri845fPkGGS67PB6PdrJ8lLU+DvI9csjSUlL+lQiqK2jKagt51BiuR5S0pR4tsInECgYEAt1YcsOLftdNBzjls5Rni0+q03vHN8LEf7YvOAY2+a2oiYJm9QN+OF8iJMg46TjKi5C1uWMH+OHVTP57EMC8lD7gfNcJIGNjHxGZNexBC9bPv45l+/YsYMLwl6XqrrRc2rlyUiyo4ndqUPvG/6WZGYsBMvKJ4oTVsfJViufWV3EECgYEAp9NWn8nO04s9rC0vCGkosjDS2K/ED5b6b5OCzhRzSFkvmFrNRXKPt74YIeWWdqlWXuIyTF6KDyvMy1G3YiBhmvIfnkknk9oqxHaG+tfFol8d2hZ2daww6ypQZKm5Do0ws58DJ98Pw6N5UjjS2VGrak+bBuWPSHtGs21C7g65tRECgYBhNKsprmDmywgNC62NG1iE++DChHqor4E6NfIYKMtZsIBhr6IEj4OLYKw9egW4CGkNinkDXngn/y0QgmGLGrQPzZPesRAA/I+Otp9GLK0UET+T8YK/c8xzqo5/aKc1syUu9a9cyhoSuB358bvLSIrxOPx2174V23mV5K7f4jJ/AQKBgQCCg8VDqwzkX4fgKRt8n6kiWV9kFlacOlDMsBFukf0WEUt+Vfyw/tqhn86a7c+JOUU2YV/AK4rGGgmZVgVZCZegko5b3qXm6MOUNmIllZnA6MQaEUWIsZfrYfNaDl7NReVxyRVvVAGqUKZ7KeoXbncekonwTI9tTUnz8TotsiIxkQ==",
                "json",
                "UTF-8",
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk2gwPKQeax1WHEbOSq3b+ogwI9yFt1uJI+q/Aku9iCrvG2G06Cx9jTJ/7lIiMlRTODQZSfbDTnP/p2vXobJWILFd94k4ZnoHOf9bVP2w7Bo3V8jSFm18nZrWwC+X9aqIMEGKp1DoCk/Nu5GRz9EBh5CA64sUCx9LaJNIVjXkhpQBaqrN+sgoajp/JaiUbjwpyFnwCfCKPLV2mTO45LH+ZSD8EAYpAvPJf6IC6yVw/7yvmU1D6CuJaCxwtScYKYiFub4zVW+4MLu1AR/QtcwgQy3IKWh7RWDTjuw4ELAFWxzjbpfv3hbjyqYVt8rR000V0co9nEhH0zEJ0sX2kT8h9wIDAQAB",
                "RSA2");

//          AlipayClient alipayClient = new DefaultAlipayClient(
//            "https://openapi.alipay.com/gateway.do"
//            ,"2021003196665108",
//            "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCB+ilkCLr98G+6hUjSYACc9M3orIkMzpK/jYQ+Wk2fkNjM6jEr4rpatMdevKryMtr1P/By8LqZxVFp/uMhFdHyvlH7hCHP6aSrupZAqvzSY8BKmMrDl0Z4mLwwtyDKolKfK+UBipExYkDBqfV/OaebuzlHHdVl6dhFkwgQWbUJfr32hiIavOsVviwVKimSwgod9v8l0djaO/0+cifmqsfUbOxEzWbjhtIWcyvSIs7Rk5AVtam9yX/sHnIf0xaHc5j1Lyz2WAnWGPx767uAoqhdCa8Kh5bSKD/zdGoW7xf4J7Imd5cRGN8WghmUvI6AvHJ83jsrrHkbtqM4foYLGFJrAgMBAAECggEAYED25/rDJ40n4JQVwp2Ptqxf1D/5Wj+cUzikx1wugc1NkCqacWp9IPEhd9n2KlhY6CgKk8QMHBYQ3ZMBdp3nFYG1yrImLAdViEssPAWkJtXyMAwIlGHxsRtCujzTjtw4nWFvPP312gFt/T007ZuvsNcsaqsAPnG3VIa3AQy90aIsnjXVKsktBzj+Y8ZtA5Y7tn1g5lCXgNlM1LQaMXTPQjdonMey/OvuHPL3SwowDMUDkx1sDbnZVaumUdVj5F+41HY9jnQPHCYdzsJgAi/v10XmCPMg9Vemufq5aiJV4Y22VduycOonmDuNZCiTakthnGGLhsqyxZXiIJbpdKUhSQKBgQD3PvQPK1ikd9328p0O8ISKBmjL6HHYRLPBJhQ+F66e5sCFZCIGLBhKSMMhwWasWOS3bRCl65fS+eHaWscQWUUq9BhQGJ/aL50Os3RbOX6n2TCuU+5gfwFkJXn651iFMS4j0Ad21IElOp4R/3BPXQ8/TkDl6y6KA8K3Jk1yB7zvHQKBgQCGlEeypXgppUa0GCvi0klnZv4uaODvKh4yqfS1cBDOijrpN0o5IwAaaSvfpU0h0Ux0UlK49KIriwUueO2ss1mbmoVtS8N59yD0i8THdw/nr4TPiZfmNusFd3Q3R4lzHQo8QmTLTfWWc+SMbJ/T1egTyxGGpJxp8Paur6ixlqFpJwKBgBfasAtioDvGANlZkQOm+vKiKaw6sfkur7Ub6moPON7F3p9ACPRVfsZz/LeeBDzumqqD0E5hy5UkXMEHbxtJsZ2yTUI1Df8sBtgrQjem9WxWTRcUq/QNbOHvp7Qoa+b11sDHymCRoiAoZqXP4lMV5Gm0MBi+tw/Dyx6GiIRO8NCVAoGALQAEAW5nAbXsMGgstImQVe0QbUBQhmhU9Kfz1X+FfyqljDoarYRQkoQ8UWoaooYzxGmKk6HpYBn6P5HcF3VZLzi6CNPepzfFY0AhKnlbbiM4i5T8n9QZPhi1WY6oHT/GnmOtBHYq+oYCFBp2TwUltwid8aG1U49pTPwbslYl3t0CgYEAsNaRu7dy6/NhJRuDB24u3h7HIpWFDQ3I9IJt7wGMZBWOySQ8WhuvbxkUmCkJ9lRJrTr4ECMGQRLySyV+wOCcA44lVrcI4P7NaKv9Ckc7o8KxL+amqa4Lg35j77c66fkWaJoPGK1wZI3Kbb8O5svWI2oBHefOeNUQUyyfm8kDbY4=",
//                  "json",
//            "UTF-8",
//            "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjT1V9Rn7MaXRIbrBgl02SNzMLL7hknV+31myCbSN/8ri4QVdGAShu7uRe+QkfUWaXAOg7vBtX+/iiA8dVnjcNR2dK3XgkhXRN7xm4NQSbSjC9az/4LFQ1SK5Qv5RR2MzXe6N+K7cxerBtthQY/Y65kMXcu3/fldkid4ZgV5RlbTb9Qc/vynhU3FZSNUluJVkNzX+uHekGnaMqQzEqbx9Ke8RSca4dqEeJrj4TAmXE5ecqkQubpaUD1gAd8/Y979mW9pXO0wPwr+AtH/0IhPyzVNEbiVX+DuLnLBtIcJDE3PxliS6wLt08oaZ3DdRn0CJkL/5DEOgUQFPQN17iRQ2DwIDAQAB",
//            "RSA2");
        List<String> list = new ArrayList<>();

        list.add("zq202310142018403489665024");


        for (String s:list){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            AlipayUserAgreementQueryRequest request = new AlipayUserAgreementQueryRequest();
            JSONObject qryBizContent = new JSONObject();
//        协议产品码personal_product_code + sign_scene + external_agreement_no
            qryBizContent.put("personal_product_code" ,"CYCLE_PAY_AUTH_P");
            //用户的支付宝账号对应 的支付宝唯一用户号
//        qryBizContent.put("alipay_user_id" ,"2088732548124550");
            //用户的支付宝登录账号，支持邮箱或手机号码格式
//        qryBizContent.put("alipay_logon_id" ,alipay_logon_id);
            //签约场景码
            qryBizContent.put("sign_scene" ,"INDUSTRY|DEFAULT_SCENE");
            //代扣协议中标示用户的唯一签约号
        qryBizContent.put("external_agreement_no" ,s);
            //签约第三方主体类型。对于三方协议，表示当前用户和哪一类的第三方主体进行签约。取值范围: 1. PARTNER（平台商户）; 2. MERCHANT（集团商户），集团下子商户可共享用户签约内容;
//        qryBizContent.put("third_party_type" ,"PARTNER");
            //支付宝系统中用以唯一标识用户签约记录的编号
//            qryBizContent.put("agreement_no" ,s);
            System.out.println(qryBizContent.toString());
            request.setBizContent(qryBizContent.toString());
            AlipayUserAgreementQueryResponse response = null;
            try {
                response = alipayClient.execute(request);
            } catch (AlipayApiException e) {
                e.printStackTrace();
            }
            if(response.isSuccess()){
                System.out.println(response);
                System.out.println(response.getStatus());
                System.out.println("调用成功");
            } else {
                System.out.println(response.toString());
                System.out.println("调用失败");
            }
        }



//
//        20235427941765272559
//        20235428953311864664
//        20235429954162703114

//        AlipayUserAgreementExecutionplanModifyRequest request = new AlipayUserAgreementExecutionplanModifyRequest();
//        JSONObject qryBizContent = new JSONObject();
//        //商户下一次扣款时间
//        qryBizContent.put("deduct_time" ,"2023-07-01");
//        //具体修改原因
////        qryBizContent.put("memo" ,"qianyu");
//        //支付宝系统中用以唯一标识用户签约记录的编号
//        qryBizContent.put("agreement_no" ,"20235429972026648339");
//
//        request.setBizContent(qryBizContent.toString());
//        AlipayUserAgreementExecutionplanModifyResponse  response = null;
//        try {
//            response = alipayClient.execute(request);
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        }
//        if(response.isSuccess()){
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//        }



    }



    /**
     * 原路退款
     * @param zfbKeyVo 支付宝支付参数
     * @param refundAmount 退款金额
     * @return
     */
    public static DoTradeRefundResVO doTradeRefund(ZfbKeyVo zfbKeyVo ,String orderId , String alitradeno ,Integer refundAmount) {
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayTradeFastpayRefundQueryRequest qryReq = new AlipayTradeFastpayRefundQueryRequest();
        JSONObject qryBizContent = new JSONObject();
        qryBizContent.put("trade_no", alitradeno);//支付宝订单号
        qryBizContent.put("out_request_no", orderId);//商家订单号
        qryReq.setBizContent(qryBizContent.toString());
        AlipayTradeFastpayRefundQueryResponse qryRsp = new AlipayTradeFastpayRefundQueryResponse();
        // gmtRefundPay
        log.info("\n退款申请响应 code: {}, msg: {}\nsub_code: {}, sub_msg: {}", qryRsp.getCode(), qryRsp.getMsg(), qryRsp.getSubCode(), qryRsp.getSubMsg());

        if (!qryRsp.isSuccess()) {
            return new DoTradeRefundResVO(false, "退款失败1", qryRsp.getBody());
        }
        String refundStatus = qryRsp.getRefundStatus();
        if ("REFUND_SUCCESS".equals(refundStatus)) {
            return new DoTradeRefundResVO(true, "退款成功", qryRsp.getBody());
        }
        AlipayTradeRefundRequest req = new AlipayTradeRefundRequest();
        JSONObject bizContent = new JSONObject();
        BigDecimal rechargeCountFen = new BigDecimal(refundAmount);
        BigDecimal rechargeCountYuan = rechargeCountFen.divide(new BigDecimal(100));
        bizContent.put("trade_no", alitradeno);
        bizContent.put("refund_amount", rechargeCountYuan);
        bizContent.put("out_request_no", orderId);
        req.setBizContent(bizContent.toString());
        AlipayTradeRefundResponse rsp = null;
        try {
            rsp = alipayClient.execute(req);
        } catch (AlipayApiException e) {
            log.info("发起退款请求失败: {}\t {}", e.getErrCode(), e.getErrMsg());
            return new DoTradeRefundResVO(false, qryRsp.getSubMsg(), qryRsp.getBody());
        }
        log.info("支付宝退款响应:" + rsp.getBody());
        if (rsp.isSuccess()) {
            return new DoTradeRefundResVO(true, rsp.getMsg(), rsp.getBody());
        } else {
            return new DoTradeRefundResVO(false, rsp.getSubMsg(), rsp.getBody());
        }
    }

    /**
     * 支付宝个人协议页面签约接口
     * @param zfbKeyVo 支付宝支付参数
     * @param externalAgreementNo 商户签约号
     * @param userPhone 用户标识
     * @param periodRuleParams 周期管控规则参数
     * @param notifyUrl
     * @throws AlipayApiException
     */
    public static AlipayUserAgreementPageSignResponse AlipayUserAgreementPageSignRequest(ZfbKeyVo zfbKeyVo , String externalAgreementNo
            , String userPhone , String notifyUrl , PeriodRuleParams periodRuleParams){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);

        AlipayUserAgreementPageSignRequest request = new AlipayUserAgreementPageSignRequest();
        request.setNotifyUrl(notifyUrl);

        JSONObject bizContent = new JSONObject();
        //销售产品码，商户签约的支付宝合同所对应的产品码。
        bizContent.put("product_code", "GENERAL_WITHHOLDING");
        //个人签约产品码，商户和支付宝签约时确定，商户可咨询技术支持。
        bizContent.put("personal_product_code", "GENERAL_WITHHOLDING_P");
        //协议签约场景，商户可根据 代扣产品常见场景值 选择符合自身的行业场景。
        bizContent.put("sign_scene", "INDUSTRY|DEFAULT_SCENE");
        //用户在商户网站的登录账号，用于在签约页面展示，如果为空，则不展示
        if (StringUtils.isNotEmpty(userPhone)){
            bizContent.put("external_logon_id", userPhone);
        }
        //商户签约号，代扣协议中标示用户的唯一签约号（确保在商户系统中唯一）。
        bizContent.put("external_agreement_no", externalAgreementNo);
        //当前用户签约请求的协议有效周期。整形数字加上时间单位的协议有效期，从发起签约请求的时间开始算起。目前支持的时间单位：1. d：天 2. m：月 如果未传入，默认为长期有效。
//        bizContent.put("sign_validity_period", "1m");
        //协议生效类型, 用于指定协议是立即生效还是等待商户通知再生效. 可空, 不填默认为立即生效.DIRECT: 立即生效.
        //NOTICE: 商户通知生效, 需要再次调用alipay.user.agreement.sign.effect （支付宝个人协议签约生效接口）接口推进协议生效.
//        bizContent.put("agreement_effect_type", "DIRECT");


        //周期管控规则参数
        JSONObject period_rule_params = new JSONObject() ;
        //周期类型period_type是周期扣款产品必填，枚举值为DAY和MONTH。
        //DAY即扣款周期按天计，MONTH代表扣款周期按自然月。
        //与另一参数period组合使用确定扣款周期，例如period_type为DAY，period=30，则扣款周期为30天；period_type为MONTH，period=3，则扣款周期为3个自然月。
        //自然月是指，不论这个月有多少天，周期都计算到月份中的同一日期。例如1月3日到2月3日为一个自然月，
        // 1月3日到4月3日为三个自然月。注意周期类型使用MONTH的时候，计划扣款时间execute_time不允许传28日之后的日期（可以传28日），以此避免有些月份可能不存在对应日期的情况。
        period_rule_params.put("period_type", periodRuleParams.getPeriodType());
        period_rule_params.put("period", periodRuleParams.getPeriod());
        //首次执行时间execute_time是周期扣款产品必填，即商户发起首次扣款的时间。精确到日，格式为yyyy-MM-dd结合其他必填的扣款周期参数，会确定商户以后的扣款计划。发起扣款的时间需符合这里的扣款计划。
        period_rule_params.put("execute_time", periodRuleParams.getExecuteTime());
        //单次扣款最大金额single_amount是周期扣款产品必填，即每次发起扣款时限制的最大金额，单位为元。商户每次发起扣款都不允许大于此金额。
        period_rule_params.put("single_amount", periodRuleParams.getSingleAmount());
        //总金额限制，单位为元。如果传入此参数，商户多次扣款的累计金额不允许超过此金额。
        period_rule_params.put("total_amount", periodRuleParams.getTotalAmount());
        //总扣款次数。如果传入此参数，则商户成功扣款的次数不能超过此次数限制（扣款失败不计入）。
        period_rule_params.put("total_payments", periodRuleParams.getTotalPayments());
        bizContent.put("period_rule_params", period_rule_params);


        //目前支持以下值：1. ALIPAYAPP （钱包h5页面签约）2. QRCODE(扫码签约)3. QRCODEORSMS(扫码签约或者短信签约)
        JSONObject accessParams = new JSONObject();
        accessParams.put("channel", "ALIPAYAPP");
        bizContent.put("access_params", accessParams);

        request.setBizContent(bizContent.toString());
        AlipayUserAgreementPageSignResponse response = null;
        try {
            response = alipayClient.pageExecute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        System.out.println(response.getBody());
        if (response.isSuccess()) {
            System.out.println("调用成功");
            return response ;
        } else {
            System.out.println("调用失败");
            return null ;
        }
    }


    /**
     * 支付宝个人代扣协议查询接口
     * @param zfbKeyVo 支付宝支付参数
     * @param alipay_user_id 支付宝唯一用户号
     * @param alipay_logon_id 用户的支付宝登录账号
     * @param external_agreement_no 代扣协议中标示用户的唯一签约号
     * @param agreement_no 支付宝系统中用以唯一标识用户签约记录的编号
     *
     * @throws AlipayApiException
     */
    public static void AlipayUserAgreementQuerySignRequest(ZfbKeyVo zfbKeyVo , String alipay_user_id
            , String alipay_logon_id , String external_agreement_no, String agreement_no){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayUserAgreementQueryRequest request = new AlipayUserAgreementQueryRequest();
        JSONObject qryBizContent = new JSONObject();
        //协议产品码
        qryBizContent.put("personal_product_code" ,"GENERAL_WITHHOLDING_P");
        //用户的支付宝账号对应 的支付宝唯一用户号
        qryBizContent.put("alipay_user_id" ,alipay_user_id);
        //用户的支付宝登录账号，支持邮箱或手机号码格式
        qryBizContent.put("alipay_logon_id" ,alipay_logon_id);
        //签约场景码
        qryBizContent.put("sign_scene" ,"INDUSTRY|DEFAULT_SCENE");
        //代扣协议中标示用户的唯一签约号
        qryBizContent.put("external_agreement_no" ,external_agreement_no);
        //签约第三方主体类型。对于三方协议，表示当前用户和哪一类的第三方主体进行签约。取值范围: 1. PARTNER（平台商户）; 2. MERCHANT（集团商户），集团下子商户可共享用户签约内容;
        qryBizContent.put("third_party_type" ,"PARTNER");
        //支付宝系统中用以唯一标识用户签约记录的编号
        qryBizContent.put("agreement_no" ,agreement_no);

        request.setBizContent(qryBizContent.toString());
        AlipayUserAgreementQueryResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }


    /**
     * 周期性扣款协议执行计划修改接口
     * @param zfbKeyVo 支付宝支付参数
     * @param memo 具体修改原因
     * @param deduct_time 商户下一次扣款时间
     * @param agreement_no 支付宝系统中用以唯一标识用户签约记录的编号
     *
     * @throws AlipayApiException
     */
    public static AlipayUserAgreementExecutionplanModifyResponse AlipayUserAgreementExecutionplanModifyRequest(ZfbKeyVo zfbKeyVo , String deduct_time
            , String memo , String agreement_no){
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayUserAgreementExecutionplanModifyRequest request = new AlipayUserAgreementExecutionplanModifyRequest();
        JSONObject qryBizContent = new JSONObject();
        //商户下一次扣款时间
        qryBizContent.put("deduct_time" ,deduct_time);
        //具体修改原因
        qryBizContent.put("memo" ,memo);
        //支付宝系统中用以唯一标识用户签约记录的编号
        qryBizContent.put("agreement_no" ,agreement_no);

        request.setBizContent(qryBizContent.toString());
        AlipayUserAgreementExecutionplanModifyResponse  response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return response;
//        if(response.isSuccess()){
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//        }
    }


    /**
     * 支付宝个人代扣协议解约接口
     * @param zfbKeyVo 支付宝支付参数
     * @param alipay_user_id 支付宝唯一用户号
     * @param external_agreement_no 代扣协议中标示用户的唯一签约号
     * @param agreement_no 支付宝系统中用以唯一标识用户签约记录的编号
     *
     * @throws AlipayApiException
     */
    public static void AlipayUserAgreementUnsignRequest(ZfbKeyVo zfbKeyVo , String alipay_user_id
            , String external_agreement_no, String agreement_no){

//        log.info("zfbKeyVo:" + zfbKeyVo);
//        log.info("external_agreement_no:" + external_agreement_no);
//        log.info("agreement_no:" + agreement_no);
//        log.info("agreement_no:" + alipay_user_id);
        AlipayClient alipayClient = getAlipayClient(zfbKeyVo);
        AlipayUserAgreementUnsignRequest request = new AlipayUserAgreementUnsignRequest();
        JSONObject qryBizContent = new JSONObject();
        //协议产品码
        qryBizContent.put("personal_product_code" ,"GENERAL_WITHHOLDING_P");
//        //用户的支付宝账号对应 的支付宝唯一用户号
        qryBizContent.put("alipay_user_id" ,alipay_user_id);
        //签约场景码
        qryBizContent.put("sign_scene" ,"INDUSTRY|DEFAULT_SCENE");
        //代扣协议中标示用户的唯一签约号
        qryBizContent.put("external_agreement_no" ,external_agreement_no);
        //签约第三方主体类型。对于三方协议，表示当前用户和哪一类的第三方主体进行签约。取值范围: 1. PARTNER（平台商户）; 2. MERCHANT（集团商户），集团下子商户可共享用户签约内容;
        qryBizContent.put("third_party_type" ,"PARTNER");
        //支付宝系统中用以唯一标识用户签约记录的编号
        qryBizContent.put("agreement_no" ,agreement_no);

        request.setBizContent(qryBizContent.toString());
        AlipayUserAgreementUnsignResponse  response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }

    /**
     *
     * @param orderId 订单ID
     * @param phone 转账支付宝账号
     * @param name 转账支付宝名字
     * @param money 转账金额
     * @param msg 转账说明
     * @param zfbKeyVo 支付宝支付参数
     * @return
     */
    public static TransferRequestDto transferRequest(String orderId , String phone, String name ,
                                              Integer money , String msg , ZfbKeyVo zfbKeyVo ) {
        TransferRequestDto transferRequestDto = new TransferRequestDto() ;
        try {

            transferRequestDto.setZfbKeyVo(zfbKeyVo);
            transferRequestDto.setOrderId(orderId);
            String prkey = zfbKeyVo.getJavaKey();

            //支付宝公钥证书文件路径
            String certPath = zfbKeyVo.getCertPath();
            //应用公钥证书路径
            String publicCertPath = zfbKeyVo.getPublicCertPath();
            //支付宝CA根证书文件路径
            String rootCertPath= zfbKeyVo.getRootCertPath();
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");  //gateway:支付宝网关（固定）https://openapi.alipay.com/gateway.do
            certAlipayRequest.setAppId(zfbKeyVo.getAppId());  //APPID 即创建应用后生成,详情见创建应用并获取 APPID
            certAlipayRequest.setPrivateKey(prkey);  //开发者应用私钥，由开发者自己生成
            certAlipayRequest.setFormat("json");  //参数返回格式，只支持 json 格式
            certAlipayRequest.setCharset("UTF-8");  //请求和签名使用的字符编码格式，支持 GBK和 UTF-8
            certAlipayRequest.setSignType("RSA2");  //商户生成签名字符串所使用的签名算法类型，目前支持 RSA2 和 RSA，推荐商家使用 RSA2。
            certAlipayRequest.setCertPath(certPath); //应用公钥证书路径（app_cert_path 文件绝对路径）
            certAlipayRequest.setAlipayPublicCertPath(publicCertPath); //支付宝公钥证书文件路径（alipay_cert_path 文件绝对路径）
            certAlipayRequest.setRootCertPath(rootCertPath);  //支付宝CA根证书文件路径（alipay_root_cert_path 文件绝对路径）
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);

            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
            Random rand = new Random();

            Double trans_amount = money.doubleValue()/100.0 ;
            request.setBizContent("{" +
                    "\"out_biz_no\":\""+orderId+"\"," +
                    "\"trans_amount\":"+trans_amount+"," +
                    "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
                    "\"biz_scene\":\"DIRECT_TRANSFER\"," +
                    "\"order_title\":\"转账\"," +
                    "\"payee_info\":{" +
                    "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
                    "\"identity\":\""+phone+"\"," +
                    "\"name\":\""+name+"\"," +
                    "}," +
                    "\"remark\":\""+msg+"\"," +
                    "\"business_params\":\"{\\\"payer_show_name_use_alias\\\":\\\"true\\\"}\"" +
                    "}");
            AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
            transferRequestDto.setMsg(response.getSubMsg());
            if (response.isSuccess()) {
                log.info("支付宝转账成功" + response.getSubMsg());
                transferRequestDto.setIstrue(true);
            } else {
                log.info("支付宝转账失败"+response.getSubMsg());
                transferRequestDto.setIstrue(false);
            }
            return transferRequestDto ;
        }catch (Exception e){
            e.printStackTrace();
            transferRequestDto.setIstrue(false);
            transferRequestDto.setMsg("转账失败");
            return transferRequestDto ;

        }

    }

//    public static void main(String[] args) {
//        AlipayClient alipayClient = new DefaultAlipayClient(
//                "https://openapi.alipay.com/gateway.do"
//                ,"2021003196662071",
//                "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCOite1QO2XdwjFq6Ql5hQ6SIK32pvY0Ku+JYms8gm3y/M3RlE6OeYs07NSJn0q2ufrm2287AggQv66E+WUsosgc4PYNxZpeF5kcGaYqaLEHa56Kxzld8kfwJZ5pCjscYsFmMHpfrVHK6UZpuU5QfNG4BQeddtBO5I2v6X/lAB5we3h1Hfw+GLHrGxPRHgk1arP1EJ1miAepVTrSX4U5ihiaTFa9SJMZ7POPx3BHl5QIJhbJTMV1s7UzuNDKxDZLwr27QKj3Fvp5Fy5CcNLNjJziqZfloP8Bc9PvHNTI6iBNuZuAIkDptCFmpu3Ag3WsCCLq+6h6owmWYErnI4pokTzAgMBAAECggEAY7VFbHlteRz/2t3UpdoKXjaokZjumTxmVk0FwB9SoumcSRb77MHhe4vejOF1fsu/nTSND7D/gim660jNuDUoUtva5xyppb9YL+PcMH/A5nRovvZ3cSBYZMifuZkWM0a9W33ebsl+Xrlt9MKk52d1mCdYi3Ifm8Li5T8sC9podsIgrQ/FNt630ehj5pUxc6px2PrHK3X+lnA7tiWAMk5nOrax6o+hCjmaBIt17jdI5fFV2YP+xIJqmb3eS5by84QbKjEVyN7xaA8qKw52G3rzRRqicSERZPwVHFq3eKfy95MNYVePJWcaybhe8ru9migFYARcHfA+V0HTddo1QldCOQKBgQDCcu3v6+Ng9Dr22wCp2i7myg6yjUG+qGn3PgCn66fRWPlPC1/wVscC4jCO6POLIL2c/tdiK4H+dG3B1RPqiQriozgQa6hha5bk5HO2+LN8hPorsvQo0Lpf6eULs31ex3z8E3HbT5XLAmqAdVyHxBPP2q1UkzjB1gYVLoZ9vuX8DQKBgQC7qbB1DVSV+plWUmxysBtt92qpExj4keiYTdkZTro39a+WABOO8x3lEqWqdeCR9w6GxGx2BGuGTNfOs7a9XAvt26He01o++S0EPu34voEtJ+jrgBoyhsYMb7iRwrBE6h0nZK0noAdZN1X20YWI/P74OwuALww7Tw6rd4X3ggwE/wKBgAgPtbeVovaZCXzEdZGVHw6oX9WdL5WU69e5NVPA3FM8ihFx2kdfgZ6n+/VgyQACmnnQwuMqBJilAQvhJpM5nT7qH1/m5rMrP7U7l2SFiQNni+uV3rN2e9OQIdPLXC46vP7CW50I/p/M+NdchjqGsX+ThE4WUGsQ0W29YQwDhwtdAoGAJYaUG4Pz4x2+Zc2LlA91HLM5599CwgnjOflvLSlaAXCmkNcpEg+5baIh8Ikrw+RkSjyi96KAodVh3hp/szPhysl9f+JBjJAlGVFAItptWEs/vz/ZfTsIBVqdzL/ioZUzCTqPiXntnkB7dySEkFUO4zJjZVmDF6UCaPU4m7qsjp8CgYBT0JVllzkh7HjP73rGqw+/za1slKnzkP6cCbooy2d1jLNUOxh3HPsKbjCE3GIDPqwNt2EBoH+jUME9nKWsibn0jzZIVCKMNCa7cMqdvUoUqBHxKn1a6d4IicN7uMeWZkziPszAq5/w21YSjIvZmOcb29cAitDvCK82KtYdWE5hTg==",
//                "json",
//                "UTF-8",
//                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA19U5RGYDMlhNHL9oJMtZuYRp0qmOfq+UQRqKg/kfXrW0BiN3DYawKOWDnq+grOPzmef26HLT93KtHvp2heMX3KE3bXDQC6VgBdV9tDAesVQ6symOUbDnw0tIU1MzDPZHKgMzq9/6rhjZFJtJwwhmvkAhavE3xYh+wUoiWxAQuWJ0ezAqMhQpqdi/TFw7gM4FhePKt3XN7ALL8rbTw4Tik7zC8V1Q/9sC78rdCFSb5/KGsE078jUAR2EgB40sXRPThZPHRudNavkFRsxQrvJCzfh68EUWPKo9adVC8FH3O2V+jUqzbnWVcHXx/x/+bZZN82NJzcVFj7yWMaTR0NvnCQIDAQAB",
//                "RSA2");
//        AlipayUserAgreementUnsignRequest request = new AlipayUserAgreementUnsignRequest();
//        JSONObject qryBizContent = new JSONObject();
//        //协议产品码
//        qryBizContent.put("personal_product_code" ,"GENERAL_WITHHOLDING_P");
////        //用户的支付宝账号对应 的支付宝唯一用户号
//        qryBizContent.put("alipay_user_id" ,"2088122185945106");
////        //用户的支付宝登录账号，支持邮箱或手机号码格式
////        qryBizContent.put("alipay_logon_id" ,alipay_logon_id);
//        //签约场景码
//        qryBizContent.put("sign_scene" ,"INDUSTRY|DEFAULT_SCENE");
//        //代扣协议中标示用户的唯一签约号
//        qryBizContent.put("external_agreement_no" ,"zq202305262130363439333376");
//        //签约第三方主体类型。对于三方协议，表示当前用户和哪一类的第三方主体进行签约。取值范围: 1. PARTNER（平台商户）; 2. MERCHANT（集团商户），集团下子商户可共享用户签约内容;
//        qryBizContent.put("third_party_type" ,"PARTNER");
//        //支付宝系统中用以唯一标识用户签约记录的编号
//        qryBizContent.put("agreement_no" ,"20235326943328962110");
//
//        request.setBizContent(qryBizContent.toString());
//        AlipayUserAgreementUnsignResponse  response = null;
//        try {
//            response = alipayClient.execute(request);
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        }
//        if(response.isSuccess()){
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//        }
//    }





}
